<?php
	require_once("header.php");
	
	$pageurl = "home";
	if (isset($_GET['p']))
		$pageurl = addslashes($_GET['p']);
	
	$pageinfo = query_to_hash("SELECT id, parent, author, title, content, security_level, security_group FROM dcms_pages WHERE urltitle='$pageurl';");
	
	if ($pageinfo === false) die ("Page not found in database.");
	
	if (check_permission($pageinfo['security_level'], $pageinfo['security_group']))
	{
		$scriptresult = evaluate_and_capture($pageinfo['content']);
		$scriptresult = obfuscate_email_addresses($scriptresult);
	}
	else
	{
		$scriptresult = "You are not allowed to view this page.";
	}
	
	render_template("header.inc", array('$title' => $pageinfo['title']));
	render_template("body.inc", array(
		'$title' => $config_site_name,
		'$menu' => generate_menu(),
		'$login' => generate_login(),
		'$content' => get_template("page.inc", array(
			'$pagetitle' => $pageinfo['title'],
			'$pagecontent' => $scriptresult))
	));
	render_template("footer.inc", array());
?>
